package cn.poco.pepsi.service.impl;

import java.io.InputStream;
import java.util.ArrayList;

import android.util.Log;
import cn.poco.pepsi.bean.Bolg;
import cn.poco.pepsi.bean.Follow;
import cn.poco.pepsi.bean.Guest;
import cn.poco.pepsi.bean.Member;
import cn.poco.pepsi.service.IMember;
import cn.poco.pepsi.util.ResponseResult;
import cn.poco.pepsi.util.UrlConnectionUtil;
import cn.poco.pepsi.util.UrlMatchUtil;
import cn.poco.pepsi.util.xmlpared.BolgXmlparse;
import cn.poco.pepsi.util.xmlpared.FollowXmlparse;
import cn.poco.pepsi.util.xmlpared.GetMemberByPocoIdXmlparse;
import cn.poco.pepsi.util.xmlpared.GuestXmlparse;


public class MemberImpl implements IMember {

	@Override
	public Member getMemberByPocoId(int uid, int vid) throws Exception {
		String path=GETMEMBERBYPOCOID.replace("#a", String.valueOf(uid));
		if (vid!=0) {
			path=path+"&vid="+vid;
		}
		path=UrlMatchUtil.matchUrl(path);
		Log.i("impl", path);
		return GetMemberByPocoIdXmlparse.getXml(UrlConnectionUtil.getRequest(path));
	}

	@Override
	public ArrayList<Guest> getGuestsByPocoId(int uid,int s,int l) throws Exception {
		String path=IMember.GETGUESTSBYPOCOID.replace("#a", String.valueOf(uid)).replace("#b", String.valueOf(s)).replace("#c", String.valueOf(l));
		path=UrlMatchUtil.matchUrl(path);
		Log.i("impl", path);
		return GuestXmlparse.getXml(UrlConnectionUtil.getRequest(path));
	}

	@Override
	public ArrayList<Bolg> getBolgByPocoId(int uid, int s, int l) throws Exception {
		String path=IMember.GETZuoPingBYPOCOID.replace("#a", String.valueOf(uid)).replace("#b", String.valueOf(s)).replace("#c", String.valueOf(l));
		path=UrlMatchUtil.matchUrl(path);
		Log.i("impl", path);
		return BolgXmlparse.getXml(UrlConnectionUtil.getRequest(path));
	}

	@Override
	public ArrayList<Follow> getFollows(int uid, int vid,int followed,int s,int l) throws Exception{
		String path=IMember.GETFollowBYPOCOID.replace("#a", String.valueOf(uid)).replace("#b", String.valueOf(vid)).replace("#d", String.valueOf(followed)).replace("#e", String.valueOf(s)).replace("#f", String.valueOf(l));
		path=UrlMatchUtil.matchUrl(path);
		Log.i("impl", path);
		return FollowXmlparse.getXml(UrlConnectionUtil.getRequest(path));
	}
	
	public boolean setFollowing(String userid , String fid , String add)throws Exception{
		String path=SETFOLLOW.replace("#a", userid).replace("#b", fid).replace("#c", add);
		path=UrlMatchUtil.matchUrl(path);
		Log.i("impl", path);
		InputStream inputStream  =  UrlConnectionUtil.getRequest(path);
		return ResponseResult.parseXML(inputStream);
	}
}
